﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZSZ.DTO;
using ZSZ.Iservice;
using ZSZ.Service.Entity;

namespace ZSZ.Service
{
    public class CommunityService : ICommunityService
    {
        private CommunityDTO ToDTO(CommunitiesEntity e) {
            CommunityDTO dto = new CommunityDTO();
            dto.BuiltYear = e.BuiltYear;
            dto.CreateTime = e.CreateDatatime;
            dto.Id = e.Id;
            dto.Location = e.Location;
            dto.Name = e.Name;
            dto.RegionID = e.RegionId;
            dto.Traffic = e.Traffic;
            return dto;
        }
        public CommunityDTO[] GetByRegionId(long id)
        {
            using (ZSZDBcontext ct = new ZSZDBcontext())
            {
                CommonService<CommunitiesEntity> cs = new CommonService<CommunitiesEntity>(ct);
                return cs.GetAll().Include(c => c.Region).AsNoTracking().Where(c => c.Region.Id == id).ToList().Select(d=>ToDTO(d)).ToArray();
            }
        }

        
    }
}
